package org.example.cotroller.comment;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.Comment;
import org.example.entity.PageBean;
import org.example.entity.Result;
import org.example.service.CommentService;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    /**
     * 删除评论
     * */
    @GetMapping("/{commentId}")
    public Result deleteComment(@PathVariable Integer commentId) {
        log.info("删除 commentId:{}", commentId);
        if (commentService.deleteComment(commentId))
            return Result.success();
        else return Result.error("删除失败");
    }

    /**
     * 按分类分页查询评论列表
     * */
    @GetMapping("")
    public Result<PageBean<Comment>> getCommentListByReason(@RequestParam(value = "commentIdBegin",required = false, defaultValue = "")String commentIdBegin,
                                                            @RequestParam(value = "commentIdEnd",required = false, defaultValue = "")String commentIdEnd,
                                                            @RequestParam(value = "commentText",required = false, defaultValue = "")String commentText,
                                                            @RequestParam(value = "goodsId",required = false, defaultValue = "")String goodsId,
                                                            @RequestParam(value = "beginTime",required = false, defaultValue = "")String beginTime,
                                                            @RequestParam(value = "endTime",required = false, defaultValue = "")String endTime,
                                                            @RequestParam(value = "pageSize",required = false, defaultValue = "10") Integer pageSize,
                                                            @RequestParam(value = "page",required = false, defaultValue = "1")Integer page) {
        log.info("查询订单号{}到{}，评论中含有{},商品Id为{}，评论时间{}到{}的评论",commentIdBegin,commentIdEnd,commentText,goodsId,beginTime,endTime);
        return Result.success(commentService.getCommentListByReason(pageSize,page,commentIdBegin,commentIdEnd,commentText,goodsId,beginTime,endTime));

    }



}
